﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using Ks.Fs.Core.Data.Provider;
using Ks.Fs.Entity;
using System.Data;
using Ks.Fs.Core.Data.SqlDataProvider.Mapper;

namespace Ks.Fs.Core.Data.SqlDataProvider
{
    public partial class SqlDataProvider : IDataProvider
    {
        
        //public int SaveOrUpdateFile(File obj)
        //{
        //    string query = "File_SaveOrUpdate";
        //    object _id = DataHelper.ExecuteScalar(query,obj.Id,obj.Filename,obj.FolderId,obj.Size,obj.LastModified,obj.Owner,obj.PhysicalFile);
        //    if (_id != null) return Convert.ToInt32(_id);
        //    return -1;
        //}

        //public bool DeleteFile(int FileId)
        //{
        //    string query = "File_Delete";
        //    int rowAffected = DataHelper.ExecuteNonQuery(query,FileId);
        //    if (rowAffected > 0) return true;
        //    return false;
        //}

        //public List<File> GetFiles(int FolderId,int SortBy, bool IsSortAscending, int PageSize, int PageIndex)
        //{
        //    string direction = "ASC";
        //    if (!IsSortAscending)
        //    {
        //        direction = "DESC";
        //    }
        //    IDataReader reader = DataHelper.ExecuteReader("File_GetByVaryParam", FolderId, SortBy, direction, PageSize, PageIndex);
        //    FileMapper map = new FileMapper();
        //    return map.Map(reader);               
        //}       

        //public File GetFile(int FileId)
        //{
        //    IDataReader reader = DataHelper.ExecuteReader("File_GetById", FileId);
        //    FileMapper map = new FileMapper();
        //    List<File> lst = map.Map(reader);
        //    if (lst.Count > 0) return lst[0];
        //    return null;
        //}

        public int SaveOrUpdateUser(User obj)
        {
            string query = "User_SaveOrUpdate";
            object _id = DataHelper.ExecuteScalar(
                query, 
                obj.Id,obj.Username,obj.Password,obj.ImageFileId,obj.Birthday,obj.CreatedOn,obj.IsActive);
            if (_id != null) return Convert.ToInt32(_id);
            return -1;
        }

        public bool DeleteUser(int UserId)
        {
            throw new NotImplementedException();
        }

        public User GetUser(int UserId)
        {
            throw new NotImplementedException();
        }




        public List<User> GetUsers()
        {
            //string direction = "ASC";
            //if (!IsSortAscending)
            //{
            //    direction = "DESC";
            //}
            //IDataReader reader = DataHelper.ExecuteReader("File_GetByVaryParam", FolderId, SortBy, direction, PageSize, PageIndex);
            //FileMapper map = new FileMapper();
            //return map.Map(reader); 
            return new UserMapper().Map(DataHelper.ExecuteReader("User_GetByVaryParam"));
        }
    }
}

